<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        html,
        body {
            height: 100%;
            width: 100%;
             background-color: #000; 
        }

        img {
            position: absolute;
        }
    </style>
</head>

<body>
    <div id="box">
        <img src="./img/girl.gif" alt="精灵">
    </div>
    <script src="./lib/jquery.min.js"></script>
    <script>
        $(function () {
            //鼠标移动时, 让精灵跟随鼠标移动
            document.onmousemove = function (e) {
                var e = e || window.event;
                // console.log(e.clientY);
                var clientX = e.clientX - ($('img').width()) / 2;
                var clientY = e.clientY - ($('img').height()) / 2;
                $('img').css({
                    'left': clientX + 'px',
                    'top': clientY + 'px'
                })
            }

            // 鼠标点击某处, 让精灵移动到该处
            // document.onmousedown = function (e) {
            //     var e = e || window.event;
            //     // console.log(e.clientY);
            //     var clientX = e.clientX - ($('img').width()) / 2;
            //     var clientY = e.clientY - ($('img').height()) / 2;
            //     $('img').animate({
            //         'left': clientX + 'px',
            //         'top': clientY + 'px'
            //     });
            // }
        })
    </script>
</body>

</html>